import 'package:flutter/material.dart';
import 'dart:ui';

import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class TopBanner extends StatefulWidget {
  final List<String> pics;

  TopBanner(this.pics);

  @override
  _TopBannerState createState() => _TopBannerState();
}

class _TopBannerState extends State<TopBanner> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 155,
      width: ScreenUtil().setWidth(750),
      child: ClipRRect(
        borderRadius: const BorderRadius.all(const Radius.circular(6.0)),
        child: this.getSwiper(),
      ),
    );
  }

  getSwiper() {
    return Swiper(
      itemCount: widget.pics.length,
      itemBuilder: (BuildContext context, int index) {
        return Container(
          height: ScreenUtil().setWidth(310),
          width: ScreenUtil().setWidth(750),
          child: ClipRRect(
            borderRadius: const BorderRadius.all(const Radius.circular(6.0)),
            child: UiUtils.cachedNetworkImage(
                ScreenUtil().setWidth(750),
                ScreenUtil().setWidth(310),
                widget.pics[
                    index]) /*Image.asset(
              Utils.getImgPath("temp_banner"),
              fit: BoxFit.fill,
            )*/
            ,
          ),
        );
      },
      controller: SwiperController(),
      scrollDirection: Axis.horizontal,
      autoplay: true,
      onTap: (index) => print('点击了第$index'),
    );
  }
}
